package main

import (
	_ "057dg/routers"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_"github.com/go-sql-driver/mysql"
	"time"
)



func init() {
	mysqluser 	:= beego.AppConfig.String("mysqluser")
	mysqlpass 	:= beego.AppConfig.String("mysqlpass")
	mysqldb 	:= beego.AppConfig.String("mysqldb")
	charset 	:= beego.AppConfig.String("charset")
	maxIdle,_ 	:= beego.AppConfig.Int("maxIdle")
	maxConn,_ 	:= beego.AppConfig.Int("maxConn")

	orm.RegisterDriver("mysql", orm.DR_MySQL)
	orm.RegisterDataBase(
		"default",
		"mysql",
		mysqluser+":"+mysqlpass+"@/"+mysqldb+"?charset="+charset,
		maxIdle,
		maxConn,
		)
	orm.SetMaxIdleConns("default", maxIdle) //根据数据库的别名，设置数据库的最大空闲连接
	orm.SetMaxOpenConns("default", maxConn) //根据数据库的别名，设置数据库的最大数据库连接 (go >= 1.2)
	orm.DefaultTimeLoc = time.UTC 	//设置为 UTC 时间
	//orm.RegisterModel(new(models.Customer),new(models.User))
}


func main() {
	isEachCreateTable,_ 	:= beego.AppConfig.Bool("isEachCreateTable")
	Debug,_ 			:= beego.AppConfig.Bool("Debug")

	orm.Debug = Debug
	orm.RunSyncdb("default",isEachCreateTable,true)
	beego.Run()
}

